package com.oco.restcontroller.api.feignclient.userinfo.client.points;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.oco.restcontroller.api.resttemplate.common.ResultMap;

@Service("HystrixPointsClient")
public class HystrixPointsClient implements IPointsClient {
	
	private static final Logger logger = LoggerFactory.getLogger(HystrixPointsClient.class);

	@Autowired
	private IPointsClient pointsClient;
	
	@Override
	@HystrixCommand(fallbackMethod = "fallbackCallOrder", commandProperties = {
			@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = HYSTRIX_TIMEOUT)})
	public Map<String, Object> queryRedeemSearch(String json) throws Exception {
		return pointsClient.queryRedeemSearch(json);
	}
	/**
	 * 该方法对于调用接口网络异常信息的处理
	 * @author zhangzhihong
	 * @email it_javasun@yeah.net
	 * @since 2016年8月17日下午3:22:30
	 */
	public Map<String, Object> fallbackCallOrder(String str,Throwable e) {
		logger.error("FAILED SERVICE CALL!"+e.getMessage(),e);
		String fallback = ("FAILED SERVICE CALL! - Crm FALLING BACK");
		return new ResultMap().failure().errmsg(fallback).map();
	}
	
	
	

}
